package torres.item;

import torres.entity.Entity;
import java.util.List;
import torres.item.effect.Effect;

/**
 * @author Torres
 * Represents an item that an Entity can pick up off the map. 
 * Maintains a list of Effects that occur when that item is used.
 */
@SuppressWarnings("serial")
public class TakeableItem extends Item
{
	private List<Effect> effects;
	
	/**
	 * Creates a new TakeableItem with the specified name.
	 * @param name The name of the TakeableItem.
	 */
	public TakeableItem(String name) {
		
		this.setName(name);
		this.setAsciiRep("T");
		//this.imageName = "sword.png";
	}
	
	
	/**
	 * Creates a new TakeableItem with the specified name and effect list.
	 * @param name The name of the TakeableItem.
	 * @param effects The effects that should occur on use.
	 */
	public TakeableItem(String name, List<Effect> effects) {
		
		this.setName(name);
		this.effects = effects;
		//this.imageName = "sword.png";
	}
	
	/**
	 * Creates a new instance of TakeableItem that is a copy of the specified TakeableItem 
	 * @param item The item to be copied.
	 */
	public TakeableItem(TakeableItem item) {
		this(item.getName(), item.getEffects());
	}
	
	/**
	 * Triggers the effect of an Entity walking on this item.
	 * @param e The Entity that is walking on this item
	 */
	public void onTouch(Entity e) {
		
		setConsumed(e.addItem(this));
	}

	
	/**
	 * Makes the specified Entity use the item.
	 * @param e The entity that is using this item.
	 */
	public void use(Entity e) {
		
		for(Effect ef : this.getEffects())
			ef.use(e);
	}
	
	
	/**
	 * Get the list of Effects that occur on use.
	 * @return The list of Effects that occur on use.
	 */
	private List<Effect> getEffects() {
		return this.effects;
	}
	
	/**
	 * Add the specified effect to the Item.
	 * @param effect The effect to be added. 
	 */
	public void addEffect(Effect effect) {
		
		effects.add(effect);
	}
	
	/**
	 * Set the effects of this item to the specified list.
	 * @param effects The new list of Effects.
	 */
	public void setEffectList(List<Effect> effects)
	{
		this.effects = effects;
	}
	
	/**
	 * Appends all of the effects in the specified list to this item's effect list.
	 * @param effects The list of Effects to be added.
	 */
	public void appendEffectList(List<Effect> effects)
	{
		this.effects.addAll(effects);
	}
	
	/**
	 * Tests to see if this Item is an EquippableItem.
	 * @return False.
	 */
	public boolean isEquippable() {
	
		return false;
	}
	
	public String getToolTip() {
		String ret="<html>Name: "+super.getName()+"<br>";
		ret += "</html>";
		return ret;
	}
}
